<template>
  <div class="app-contain">
    <!-- 第二行 -->
    <div class="two">
      <!-- 第一排搜索卡片 -->
      <el-card class="box-card">
        <el-row
          style="font-size: 15px; line-height: 2em; color: #909399"
          :gutter="60"
        >
          <el-col :span="6">
            <div class="two_left">
              <div>
                {{ itemSum }} 门
                <span>我的培训</span>
              </div>
            </div>
          </el-col>

          <el-col :span="18">
            <el-col :span="50" style="padding-left: 50px; padding-right: 30px">
              <div class="two_right">
                所属类别:
                <el-radio-group v-model="radio">
                  <el-radio-button label="全部"></el-radio-button>
                  <el-radio-button label="人力资源"></el-radio-button>
                  <el-radio-button label="职能类"></el-radio-button>
                  <el-radio-button label="经营类"></el-radio-button>
                  <el-radio-button label="市场类"></el-radio-button>
                  <el-radio-button label="财务类"></el-radio-button>
                  <el-radio-button label="营销类"></el-radio-button>
                </el-radio-group>
                <hr />
                培训名称:<el-input
                  placeholder="请输入内容"
                  style="width: 35%"
                ></el-input>
                培训状态:<el-input
                  placeholder="请输入内容"
                  style="width: 40%; maigin-left: 20px"
                ></el-input>
              </div>
            </el-col>
            <el-col :span="12">
              <div class="search" style="margin-left: 600px;maigin-top:10px">
                <el-button type="primary" icon="el-icon-search">搜索</el-button>
              </div>
            </el-col>
          </el-col>
        </el-row>
      </el-card>
    </div>
    <div class="three">
      <el-row>
        <el-col :span="3"><div class="grid-content bg-purple"></div></el-col>
        <el-col :span="20">
          <el-col :span="24">
            <el-col :span="22" v-for="(course,index) in tableData" :key="course.index" style="margin-left:93px;margin-top:20px">
              <!-- <el-input v-model="UserAndItemid.itemId" type="hidden" value="course.itemId"></el-input> -->
              <el-card :body-style="{ padding: '0px' }" class="card">
                <div class="img">
                <img :src="course.trainCover" height="150px" width="150px" />
                </div>
                <div style="padding: 20px; font-size: 12px" class="text">
                  <span style="font-size: 15px" 
                    >{{ course.trainTitle }}
                    <br /><br />
                  <span>描述：{{
                    course.trainDescription | textHandle1(course.trainDescription)
                  }}</span><br />
                  <span>项目状态：{{course.trainStatus}}</span><br />
                  <span>报名截止时间：{{(course.applyCuttime || "").split("T")[0]}}</span>
                   </span>
                </div>
                <!-- <div class="button">
                  <el-button 
                      size="medium"
                      style="margin-left:10px;"
                      type="success"
                      @click="handleClick(index, course.itemId)"
                    >学习</el-button>
                  <el-button 
                  size="medium "
                    type="danger"
                    @click="handleDelete(index,course.itemId)"
                  >删除</el-button>
                </div> -->
                <div class="button">
                  <el-button 
                      size="medium"
                      style="margin-left:10px;"
                      type="success"
                      @click="handleClick(index, course.itemId)"
                    >学习</el-button>
                  <el-button 
                  size="medium "
                    type="danger"
                    @click="handleDelete(index,course.itemId)"
                  style="margin-top: 16px !important">删除</el-button>
                </div>
              </el-card>
            </el-col>
          </el-col>
        </el-col>
        <el-col :span="1"><div class="grid-content bg-purple"></div></el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { findMyItemSum } from "@/api/user";
import { findAllUser } from "@/api/user";
import { findAllItem } from "@/api/user";
import { DeleteItemByUid } from "@/api/item"

export default {
  el: ".app-contain",
  data() {
    return {
      tableData: [], //项目数据
      itemSum: 0,
      radio:"全部",
      activeName: "项目管理",
      total: 0,
      currentPage: 1,
      formInLine: {
        page: 1,
        id: 1,
        limit: 10,
      },
      UseridAndItemid: {
        uid: 1,
        tid: 0,
      },
    };
  },
  created() {
    this.formInLine.id = this.$store.getters.userId;
    this.UseridAndItemid.uid = this.$store.getters.userId;
    this.getdata();
  },
  methods: {
    getdata() {
      findMyItemSum(this.UseridAndItemid.uid)
        .then((res) => {
          // console.log(res);
          this.itemSum = res.data;
        })
        .catch((err) => {
          console.log(err);
          alert("总数后端有错");
        }),
        findAllItem(this.formInLine)
          .then((res) => {
            console.log(res);
            this.tableData = res.data.list;

          })
          .catch((err) => {
            console.log(err);
            alert("详情后端有错");
          });
    },
    handleClick(index, iId) {
      this.$router.push({
        name: "trainDetails",
        query: {
          userId: this.UseridAndItemid.uid,
          itemId: iId,
        },
      });
    },
    handleDelete(index,iId){
      this.UseridAndItemid.tid = iId;
      DeleteItemByUid(this.UseridAndItemid).then(
        res => {
          console.log(res);
        }
      ).catch(
          err => {
            console.log(err);
          }
        );
      findMyItemSum(this.UseridAndItemid.uid)
        .then((res) => {
          // console.log(res);
          this.itemSum = res.data;
        })
        .catch((err) => {
          console.log(err);
          alert("总数后端有错");
        }),
        findAllItem(this.formInLine)
          .then((res) => {
            console.log(res);
            this.tableData = res.data.list;

          })
          .catch((err) => {
            console.log(err);
            alert("详情后端有错");
          });
      },
    handleSizeChange(val) {
      this.formInLine.limit = val;
      findAllItem(this.formInLine).then((res) => {
        console.log(res);
        this.tableData = res.data.list;
        this.currentPage = res.data.pageNum;
      });
    },
    handleCurrentChange(val) {
      this.formInLine.page = val;
      findAllItem(this.formInLine).then((res) => {
        // console.log(res);
        this.tableData = res.data.list;
        this.currentPage = res.data.pageNum;
      });
      console.log(`当前页: ${val}`);
    },
  },
  filters: { 
      /* 给左边的字段限制 */
  　　textHandle: function(val) {
      let textNew = val
      if (val.length > 40) {
        textNew = val.slice(0, 40) + '…'
      }
      return textNew
    },
    /* 给右边的字段限制 */
    textHandle1: function(val) {
      let textNew = val
      if (val.length > 30) {
        textNew = val.slice(0, 30) + '…'
      }
      return textNew
    },

  },
};
</script>

<style>
.app-contain {
  width: 100%;
  height: 2000px;
  background-color: ghostwhite;
}
.el-breadcrumb {
  font-size: 20px;
  line-height: 4;
}
.two {
  clear: both;
  margin-top: 50px;
}
.two_left {
  float: left;
  margin-left: 75px;
  width: 300px;
  height: 150px;
  background-color: deeppink;
}
.two_right {
  float: left;
  margin-top: 25px;
  margin-left: 10px;
}
.three {
  clear: both;
}
.button {
  padding: 0;
  float: right;
  margin-top: 35px;
  margin-right: 50px;
  width: 130px;
  height: 80px;
 
}
.description {
  float: left;
  margin-top: 45px;
  margin-left: 30px;
}
.men {
  font-size: 40px;
  letter-spacing: 10px;
  position: absolute;
  top: 50%;
  left: 30%;
}
#words {
  margin-top: 1.67em;
  margin-left: 120px;
}
.teo_left {
  height: 100%;
  background-color: yellow;
  width: 300px;
  margin-right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.two_left > div:first-child {
  width: 100%;
  height: 150px;
  font-size: 30px;
  color: #fff;
  position: relative;
  background-image: url(../../img/背景.jpg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.two_left > div:first-child > span:last-child {
  font-size: 16px;
  position: absolute;
  bottom: 10px;
  right: 10px;
}
.item {
  float: left;
  margin-left: 30px;
}

.text{
  float: left;
  margin-left: -130px;
}
.img{
  float: left;
  width: 30%;
}
</style>